Skip to content

[iOS] Fabric: Add missing source properties of Image#46460

Closed
zhongwuzw wants to merge 3 commits into
facebook:mainfrom
zhongwuzw:features/fix_fabric_image_source
Closed

[iOS] Fabric: Add missing source properties of Image#46460
zhongwuzw wants to merge 3 commits into
facebook:mainfrom
zhongwuzw:features/fix_fabric_image_source

Conversation

@zhongwuzw
Copy link
Copy Markdown
Contributor

Summary:

Fabric: Add missing source properties of Image

Changelog:

[IOS] [FIXED] - Fabric: Add missing source properties of Image

Test Plan:

Missing props should worked.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 12, 2024
Copy link
Copy Markdown
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There have been some feedback internally on the change, to improve this.
Could you please have a look at them and apply them?

Comment thread packages/react-native/ReactCommon/react/renderer/components/image/conversions.h Outdated
Comment on lines +127 to +131
method = [[NSString alloc] initWithBytesNoCopy:(void *)imageSource.method.c_str()
length:imageSource.method.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO]
.uppercaseString
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we just do?

Suggested change
method = [[NSString alloc] initWithBytesNoCopy:(void *)imageSource.method.c_str()
length:imageSource.method.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO]
.uppercaseString
method = [[NSString alloc] initWithUTF8String:imageSource.method.c_str()].uppercaseString;

also, no need for the ?: fallback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emm, I used no copy method because I think it can reduce one copy, if we use initWithUTF8String, it would produces twice copy operations from c_str to nsadata.

length:imageSource.body.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO];
body = [RCTConvert NSData:bodyString];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just initialize it with some NSData initializer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems no suitable initializer...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the initializer should be:

[NSData dataWithBytes:imageSource.body.c_str() length:imageSource.body.size()]

We use this also in other locations, like here

Copy link
Copy Markdown
Contributor Author

@zhongwuzw zhongwuzw Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipolleschi I updated. But they are maybe different when bytes are not a valid UTF-8 bytes?

Comment thread packages/react-native/ReactCommon/react/renderer/imagemanager/primitives.h Outdated
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in NSData initializer

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Sep 19, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cipolleschi merged this pull request in 052def0.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @zhongwuzw in 052def0

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants